var mask = null;
var count = 1
var login_user = null
$(function() { // 初始化内容
	mui.plusReady();
	mask = mui.createMask(); //遮罩层
	mui.init();
	tap_init();
	mui('#pullrefresh').pullRefresh({

		up: { //上拉加载
			height: 50, //可选.默认50.触发上拉加载拖动距离
			auto: true, //可选,默认false.自动上拉加载一次
			contentrefresh: "正在加载...",
			contentnomore: '没有更多数据了',
			callback: function() { //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
				window.setTimeout(function() {
					pullupRefresh()
				}, 500);
			}
		}

	})

	login_user = JSON.parse(localStorage.getItem('loginUser'));
	datetime_init();


})




function pullupRefresh() {

	var status = $('#status option:selected').val();
	loadSiteUseFee(status)
}


function tap_init() {

	jQuery(document).ready(function() {

		jQuery("#status").change(function() {
			mui('#pullrefresh').pullRefresh().refresh(true);
			mui('#pullrefresh').pullRefresh().enablePullupToRefresh(true)
			var status = $('#status option:selected').val();
			app.todos = []

			count = 1
			loadSiteUseFee(status)
		});

	});

	mui(".mui-scroll").on("tap", ".mui-control-item", function(e) {
		var id = this.getAttribute("data_id");
		console.log(id)

		console.log("跳转")
		
		
		window.sessionStorage.setItem("siteUseFeeId", JSON.stringify(id))
		window.location.href = "siteUseFee_form.html"
		
	});

}


var app = new Vue({
	el: '#app',
	data: {
		show: true,
		todos: []
	},
	methods: {
		// selected: function(todo) {
		// 	window.sessionStorage.setItem("siteUseFeeId", JSON.stringify(todo.id))
		// 	window.location.href = "siteUseFee_form.html"

		// }
	}
});

function loadApp(data, status) {
	console.log("data1====" + JSON.stringify(data));

	for (var i = 0; i < data.length; i++) {
		var d = data[i];
		var o = new Object();
		for (var x in d) {
			o[x] = d[x];

			switch (d.xzauditstatus) {
				case "审核中":
					o.imgsrc = '../../img/waitingimg.png';
					break;
				case "校长审核通过":
					o.imgsrc = '../../img/successimg.png'
					break;
				case "校长审核不通过":
					o.imgsrc = '../../img/errorimg.png'
					break;
				default:
					break;
			}
		}

		app.todos.push(o);
	}
}


function loadSiteUseFee(status) {

	var data = {};
	data['rows'] = 20
	data['page'] = 1
	data['schoolid'] = login_user.schoolid
	data['xzauditstatus'] = status
	console.log("场地费审批====" + JSON.stringify(data));
	jQuery.ajax({
		headers: {
			'Authorization': login_user.token
		},
		type: "POST",
		url: serverip + "fxxz/cdfAuditGrid",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {

			mask.show(); //显示遮罩层
		},
		success: function(res) {
			console.log("场地费审批列表" + JSON.stringify(res));
			mask.close(); //显示遮罩层\
			count = count + 1



			var cdfList = res.cdfList;
			loadApp(cdfList, status);




			//数据加载完成后执行的操作,隐藏加载页面,显示数据
			mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //停止正在加载
			mui('#pullrefresh').pullRefresh().enablePullupToRefresh(true); //启用上拉加载


		},

		error: function(e) {
			console.log("场地费审批列表错误" + JSON.stringify(e));
			mask.close(); //显示遮罩层
			var msg = e.responseJSON.message;
			var code = e.responseJSON.status;
			mui.alert('错误编码' + code + "\n" + "错误信息:" + msg);

		}
	});
}
